package com.peng.leetcode.tree;

import java.util.LinkedList;
import java.util.Queue;

/**
 * BSTIterator
 *
 * 173. 二叉搜索树迭代器
 *
 * @author: lupeng6
 * @create: 2021/1/28 15:11
 */
public class BSTIterator {

    public static void main(String[] args) {

    }

    private Queue<Integer> queue = new LinkedList<>();

    public BSTIterator(TreeNode root) {
        init(root, queue);
    }

    private static void init(TreeNode node, Queue queue) {
        if (node == null) {
            return;
        }
        init(node.left, queue);
        queue.offer(node.val);
        init(node.right, queue);
    }

    public int next() {
        return queue.poll();
    }

    public boolean hasNext() {
        return !queue.isEmpty();
    }
}
